import { reqCategoryList, reqGetBannerList, reqGetFloorList } from '@/api'
//home模块的小仓库
//state仓库存储数据的地方
const home = {
   state: {
      //state中的数据默认初始值不要瞎写
      categoryList: [],
      bannerList: [],
      floorList: [],
   },
   //mutations修改state唯一手段
   mutations: {
      GETCATEGORYLIST(state, categoryList) {
         state.categoryList = categoryList//截取数据
      },
      GETBANNERLIST(state, bannerList) {
         state.bannerList = bannerList
      },
      GETFLOORLIST(state, floorList) {
         state.floorList = floorList
      }
   },
   //action处理action 可以书写自己的业务逻辑,也可以处理异步
   actions: {
      async getCategoryList({ commit }) {
         let result = await reqCategoryList()
         if (result.code === 200) {
            commit("GETCATEGORYLIST", result.data)
         }
      },
      //后去首页轮播图的数据
      async getBannerList({ commit }) {
         let result = await reqGetBannerList()
         if (result.code == 200) {
            commit("GETBANNERLIST", result.data)
         }
      },
      async getFloorList({ commit }) {
         let result = await reqGetFloorList()
         if (result.code == 200) {
            commit("GETFLOORLIST", result.data)
         }
      },
   },
   //getters 可以理解为计算属性,用于简化仓库数据,让组件获取仓库的数据更加方便
   getters: {}
}

export default home